home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 342_01.zip / DIOLIB.H < prev    next >
C/C++ Source or Header  |  1993-04-03  |  5KB  |  149 lines

  1. /*-
  2.  *  ----------------------------------------------------------------------
  3.  *  File        :   DIOLIB.H
  4.  *  Creator     :   Blake Miller
  5.  *  Version     :   01.01.00        February 1991
  6.  *  Language    :   Microsoft C     Version 5.1
  7.  *  Purpose     :   Intel 8255 Compatible Digital IO Functions
  8.  *  ----------------------------------------------------------------------
  9.  *  Revision History:
  10.  *  022891 BVM  :   Modify to data array instead of individual fields.
  11.  *  022891 BVM  :   Program uses 'short' instead of 'int' so will work
  12.  *              :   on 32 bit machines.
  13.  *  091190 BVM  :   Creation
  14.  *  ----------------------------------------------------------------------
  15.  */
  16.  
  17. #if !defined (DIOLIB_H_DEFINED)
  18. #define     DIOLIB_H_DEFINED    1   /* prevent multiple inclusion   */
  19.  
  20. /*  Definitions ------------------------------*/
  21.  
  22. /*  The address definitions are set up for the 8255.
  23.  *  The base address of the 8255 should be passed to the
  24.  *  dio_init() function.  This is the 80X86 PORT address
  25.  *  where the 8255 is located.  The address used in the
  26.  *  outportb() or outp() calls ( out DX, AL where DX =
  27.  *  8255 Base Address in assembly language).
  28.  *  These are the offsets from the base address.
  29.  *  Note that these definitions also correspond to
  30.  *  the port numeric identification as well.
  31.  *  Port 0 is Port A, Port 1 is Port B, Port 2 is Port C.
  32.  *  These are also acceptable definitions where a
  33.  *  numeric port identification is required
  34.  *  ( dio_put_byte and dio_get_byte ).
  35.  */
  36.  
  37. #define DIO_PORTA   0       /* 8255 PORT A  offset  */
  38. #define DIO_PORTB   1       /* 8255 PORT B  offset  */
  39. #define DIO_PORTC   2       /* 8255 PORT C  offset  */
  40. #define DIO_CNTRL   3       /* 8255 CONTROL offset  */
  41.  
  42. #define DIO_MAXCH   3       /* 8255 has three ports */
  43.  
  44. #define DIO_SET     0x80    /* configure set bit    */
  45.  
  46. #define DIO_PA_M0   0x20    /* Port A I/O Mode 0 : Basic            */
  47. #define DIO_PA_M1   0x40    /* Port A I/O Mode 1 : Strobed          */
  48. #define DIO_PA_M2   0x60    /* Port A I/O Mode 2 : Bidirectional    */
  49. #define DIO_PB_M0   0x00    /* Port B I/O Mode 0 : Basic            */
  50. #define DIO_PB_M1   0x04    /* Port B I/O Mode 1 : Strobed          */
  51.  
  52. #define DIO_CL_IN   0x01    /* Port C Low  Input    */
  53. #define DIO_PB_IN   0x02    /* Port B      Input    */
  54. #define DIO_CH_IN   0x08    /* Port C High Input    */
  55. #define DIO_PA_IN   0x10    /* Port A      Input    */
  56.  
  57. /*  8255 Digital select mode:
  58.  *  PA 0-7 output, PB 0-7 output, PC 0-3 output, PC 4-7 output
  59.  *  ALL ports in Mode 0
  60.  */
  61. #define DIO_ALL_OP  DIO_SET
  62.  
  63. /*  8255 Digital select mode:
  64.  *  PA 0-7 input, PB 0-7 input, PC 0-3 input, PC 4-7 input
  65.  *  ALL ports in Mode 0
  66.  */
  67. #define DIO_ALL_IP  (DIO_SET | DIO_CL_IN | DIO_PB_IN | DIO_CH_IN | DIO_PA_IN)
  68.  
  69. /*  Error Definitions ------------------------*/
  70.  
  71. #define DIO_ST_OK   0x0000  /* OK                       */
  72. #define DIO_ST_BB   0x0001  /* Bad bit number           */
  73. #define DIO_ST_BP   0x0002  /* Bad port number          */
  74. #define DIO_ST_BE   0x0004  /* Bad array element number */
  75. #define DIO_ST_NM   0x0008  /* No memory available      */
  76. #define DIO_ST_MA   0x0010  /* Memory already allcoated */
  77.  
  78. /*- Data Structure ---------------------------*
  79.  *  The layout of the data closely matches the port
  80.  *  available on the I8255.  The base address and
  81.  *  status flag are extra.
  82.  */
  83. #if !defined ( DIODAT_DEFINED )
  84. typedef struct diodat_struct {
  85.  
  86.     short           base;               /* 8255 address */
  87.     short           stat;               /* status flag  */
  88.     unsigned char   mode;               /* current mode */
  89.     unsigned char   pdat[DIO_MAXCH];    /* port data    */
  90.  
  91.     } DIODAT;
  92.  
  93. #define DIODAT_DEFINED  1
  94. #endif
  95.  
  96. /*  Function Prototypes ----------------------*/
  97.  
  98. #if !defined ( DIOFNC01_C_DEFINED )
  99. extern void dio_init (DIODAT *, short);
  100. #endif
  101.  
  102. #if !defined ( DIOFNC02_C_DEFINED )
  103. extern void dio_config (DIODAT *, short, short, short, short);
  104. #endif
  105. #if !defined ( DIOFNC03_C_DEFINED )
  106. extern void dio_bitput (DIODAT *, short, short);
  107. #endif
  108. #if !defined ( DIOFNC04_C_DEFINED )
  109. extern void dio_bitget (DIODAT *, short, short *);
  110. #endif
  111.  
  112. #if !defined ( DIOFNC05_C_DEFINED )
  113. extern void dio_put_byte (DIODAT *, short, unsigned char);
  114. #endif
  115. #if !defined ( DIOFNC06_C_DEFINED )
  116. extern void dio_get_byte (DIODAT *, short, unsigned char *);
  117. #endif
  118.  
  119. #if !defined ( DIOFNC07_C_DEFINED )
  120. extern void dio_dump_bytes (DIODAT *);
  121. #endif
  122. #if !defined ( DIOFNC08_C_DEFINED )
  123. extern void dio_load_bytes (DIODAT *);
  124. #endif
  125.  
  126. #if !defined ( DIOFNC09_C_DEFINED )
  127. extern void dio_bput (short, unsigned char);
  128. #endif
  129. #if !defined ( DIOFNC10_C_DEFINED )
  130. extern void dio_bget (short, unsigned char *);
  131. #endif
  132.  
  133. #if !defined ( DIOFNC11_C_DEFINED )
  134. extern short dio_pa_aloc   (short);
  135. extern void  dio_pa_free   (void);
  136. extern short dio_pa_setadr (short, short);
  137. extern short dio_pa_bitput (short, short);
  138. extern short dio_pa_bitget (short, short *);
  139. extern short dio_pa_getptr (short, DIODAT **);
  140. extern short dio_pa_config (short, short, short, short, short);
  141. #endif
  142.  
  143. #endif  /* prevent multiple inclusion   */
  144. /*-
  145.  *  ----------------------------------------------------------------------
  146.  *  END DIOLIB.H Header File
  147.  *  ----------------------------------------------------------------------
  148.  */
  149.